/* File generated automatically by the QuickJS compiler. */

#include <stdio.h>
#include <inttypes.h>
#include "../quickjs-libc.h"

const uint32_t qjsc_test_size = 426;

const uint8_t qjsc_test[426] = {
    /* bytecode 版本号 */
    0x02,

    /* 源代码中的atom表 */
    0x0c, // atom的个数
    0x12, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x56, 0x61, 0x72, // globalVar
    0x04, 0x66, 0x31, // f1
    0x04, 0x66, 0x32, // f2
    0x02, 0x41, // A
    0x02, 0x61, // a
    0x0e, 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, // console
    0x06, 0x6c, 0x6f, 0x67, // log
    0x0c, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x31, // field1
    0x02, 0x66, // f
    0x12, 0x2e, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x6a, 0x73, // ./test.js
    0x10, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x56, 0x61, 0x72, // localVar
    0x0c, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x32, // field2

    /* function对象的熟悉 */
    0x0e, // BC_TAG_FUNCTION_BYTECODE
    /** 0000 0000 0110 0000 function flags
     * 1 has_prototype
     * 1 has_simple_parameter_list
     * 1 is_derived_class_constructor
     * 1 need_home_object
     * 
     * 2 func_kind
     * 1 new_target_allowed
     * 1 super_call_allowed
     * 
     * 1 super_allowed
     * 1 arguments_allowed
     * 1 has_debug
     * 1 backtrace_barrier
     */
    0x00, 0x06,
    0x00, // js_mode
    0x9e, 0x01, // func_name
    0x00, // arg_count=0
    0x01, // var_count=1
    0x00, // defined_arg_count
    0x04, // stack_size
    0x00, // closure_var_count
    0x03, // cpool_count 
    0xb1, 0x01, // byte_code_len
    0x01, // arg_count + var_count
    0xa0, 0x01, // var_name
    0x00, // scope_level
    0x00, // scope_next + 1
    /** var flags
     * 1 var_kind
     * 1 is_func_var
     * 1 is_const
     * 1 is_lexical
     * 1 is_captured
     */
    0x00,

    /* function body中的字节码 byte_code_buf */
    0x3f, // OP_check_define_var
    0xdf, 0x00, 0x00, 0x00, 
    0x80, // flags
    
    0x3f,
    0xe0, 0x00, 0x00, 0x00, 
    0x40, 
    
    0x3f, 
    0xe1, 0x00, 0x00, 0x00, 
    0x80, 
    
    0x3f, 
    0xe2, 0x00, 0x00, 0x00,
    0x40, 
    
    0x3f, 
    0xe3, 0x00, 0x00, 0x00, 
    0x80, 
    
    0x3e, // OP_define_var
    0xdf, 0x00, 0x00, 0x00, 
    0x82, 
    
    0xc1, // OP_fclosure8
    0x00, 
    
    0x40, // OP_define_func
    0xe0, 0x00, 0x00, 0x00, 
    0x00, 
    
    0x3e, 
    0xe1, 0x00, 0x00, 0x00, 
    0x82, 
    
    0xc1, 
    0x01, 
    
    0x40, 
    0xe2, 0x00, 0x00, 0x00, 
    0x00, 
    
    0x3e, 
    0xe3, 0x00, 0x00, 0x00,
    0x82, 
    
    0xb7, // OP_push_1
    
    0x3a, // OP_put_var_init
    0xdf, 0x00, 0x00, 0x00, 
    
    0x38, // OP_get_var
    0xe0, 0x00, 0x00, 0x00, 
    
    0xef, // OP_call0
    0x3a, 0xe1, 0x00,
    0x00, 0x00, 0x38, 0xe4, 0x00, 0x00, 0x00, 0x42,
    0xe5, 0x00, 0x00, 0x00, 0x38, 0xe1, 0x00, 0x00,
    0x00, 0xef, 0x24, 0x01, 0x00, 0xca, 0x38, 0xe2,
    0x00, 0x00, 0x00, 0x0b, 0xbe, 0x0c, 0x4c, 0xe6,
    0x00, 0x00, 0x00, 0xc1, 0x02, 0x4d, 0xe7, 0x00,
    0x00, 0x00, 0x4c, 0xe7, 0x00, 0x00, 0x00, 0x15,
    0x43, 0x3a, 0x00, 0x00, 0x00, 0xca, 0x38, 0xe2,
    0x00, 0x00, 0x00, 0x11, 0xbe, 0x0b, 0x21, 0x01,
    0x00, 0x3a, 0xe3, 0x00, 0x00, 0x00, 0x38, 0xe4,
    0x00, 0x00, 0x00, 0x42, 0xe5, 0x00, 0x00, 0x00,
    0x38, 0xe3, 0x00, 0x00, 0x00, 0x42, 0xe7, 0x00,
    0x00, 0x00, 0x24, 0x00, 0x00, 0x24, 0x01, 0x00,
    0xce, 0x28,

    /* debug info */
    0xd0, 0x03, // filename
    0x01, // line_num
    0x0e, // pc2line_len
    /* pc2line_buf */
    0x97, 0xae,
    0x00, 0x06, 0x0e, 0x3a, 0x00, 0x14, 0x0c, 0x21,
    0x28, 0x3f, 0x26, 0x53,

    0x0e, 
    0x43, 0x06, 
    0x00,
    0xc0, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
    0x08, 0x01, 0xd2, 0x03, 0x01, 0x00, 0xc0, 0x61,
    0x00, 0x00, 0xb8, 0xca, 0xc1, 0x00, 0x28, 0xd0,
    0x03, 0x03, 0x02, 0x12, 0x0f, 0x0e, 0x42, 0x06,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00,
    0x0a, 0x00, 0xd2, 0x03, 0x00, 0x09, 0x65, 0x00,
    0x00, 0x38, 0xdf, 0x00, 0x00, 0x00, 0x9e, 0x28,
    0xd0, 0x03, 0x05, 0x01, 0x03, 0x0e, 0x43, 0x06,
    0x00, 0xc4, 0x03, 0x01, 0x01, 0x01, 0x02, 0x00,
    0x00, 0x0a, 0x02, 0xc6, 0x03, 0x00, 0x01, 0x00,
    0x10, 0x00, 0x01, 0x00, 0x08, 0xca, 0xc6, 0xd2,
    0x43, 0xea, 0x00, 0x00, 0x00, 0x29, 0xd0, 0x03,
    0x0d, 0x02, 0x0d, 0x26, 0x0e, 0x43, 0x06, 0x00,
    0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x10,
    0x01, 0x10, 0x00, 0x01, 0x00, 0x08, 0xca, 0xc6,
    0x41, 0xe6, 0x00, 0x00, 0x00, 0xc6, 0x41, 0xea,
    0x00, 0x00, 0x00, 0x9e, 0x28, 0xd0, 0x03, 0x12,
    0x01, 0x0d,
};

int main(int argc, char **argv) {
  JSRuntime *rt;
  JSContext *ctx;
  rt = JS_NewRuntime();
  ctx = JS_NewContextRaw(rt);
  JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);
  JS_AddIntrinsicBaseObjects(ctx);
  JS_AddIntrinsicDate(ctx);
  JS_AddIntrinsicEval(ctx);
  JS_AddIntrinsicStringNormalize(ctx);
  JS_AddIntrinsicRegExp(ctx);
  JS_AddIntrinsicJSON(ctx);
  JS_AddIntrinsicProxy(ctx);
  JS_AddIntrinsicMapSet(ctx);
  JS_AddIntrinsicTypedArrays(ctx);
  JS_AddIntrinsicPromise(ctx);
  JS_AddIntrinsicBigInt(ctx);
  js_std_add_helpers(ctx, argc, argv);
  js_std_eval_binary(ctx, qjsc_test, qjsc_test_size, 0);
  js_std_loop(ctx);
  JS_FreeContext(ctx);
  JS_FreeRuntime(rt);
  return 0;
}

